using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//坦克基类
public abstract class TankBaseObj : MonoBehaviour
{
    public int atk;
    public int def;
    public int maxHp;
    public int hp;
    //炮台
    public Transform tankHead;
    //移动旋转速度相关
    public float moveSpeed = 10;
    public float roundSpeed = 100;
    public float headRoundSpeed = 100;
    //死亡特性对象
    public GameObject deadEff;
    /// <summary>
    /// 开火
    /// </summary>
    public abstract void Fire();

    /// <summary>
    /// 被别人攻击造成自己受伤
    /// </summary>
    /// <param name="other">攻击者</param>
    public virtual void Wound(TankBaseObj other)
    {
        int dmg = other.atk - this.def;
        if (dmg <= 0) return;
        this.hp -= dmg;
        if(this.hp <= 0)
        {
            this.hp = 0;
            //执行死亡方法
            Dead();
        }
    }
    /// <summary>
    /// 死亡
    /// </summary>
    public virtual void Dead()
    {
        Destroy(this.gameObject);
        if(deadEff != null)
        {
            //创建特效
            GameObject effObj = Instantiate(deadEff, transform.position, transform.rotation);
            //特效上可能有音效, 此处可以关联音效控制
            AudioSource audioSource = effObj.GetComponent<AudioSource>();
            if (audioSource != null)
            {
                audioSource.volume = GameDataManager.Instance.musicData.soundValue;
                audioSource.mute = GameDataManager.Instance.musicData.isOpenSound;
                audioSource.Play();
            }
        }
    }
}
